package com.ram.controller;

import com.ram.pojo.Bed;
import com.ram.pojo.BedDTO;
import com.ram.pojo.BedVO;
import com.ram.pojo.PageResult;
import com.ram.pojo.Result;
import com.ram.service.BedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/bed")
public class BedController {
    @Autowired
    private BedService bedService;

    @GetMapping("/list")
    public Result list(@RequestParam Integer roomId) {
        return Result.success(bedService.list(roomId));
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        return Result.success(bedService.getById(id));
    }

    @PostMapping
    public Result add(@RequestBody Bed bed) {
        bedService.add(bed);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody Bed bed) {
        bedService.update(bed);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        bedService.deleteById(id);
        return Result.success();
    }

    // 分页+条件查询
    @PostMapping("/page")
    public Result pageQuery(@RequestBody BedDTO dto) {
        PageResult<BedVO> pageResult = bedService.pageQuery(dto);
        return Result.success(pageResult);
    }
} 